package org.come.xingpan;

import com.tool.tcpimg.UIUtils;
import org.come.model.InternalForm;
import org.come.until.FormsManagement;
import org.come.until.MessagrFlagUntil;
import org.come.until.Music;

import javax.swing.*;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

/**
 * 星盘主面板<br>
 * 窗口编号:120<br>
 * <p>
 * Title : JframeXingCardMain
 * </p>
 *
 * @author : HGC
 * @date : 2019年8月6日 上午10:36:16
 * @version : 1.0.0
 */
public class JframeXingCardMain extends JInternalFrame implements MouseListener {

    private int first_x, first_y;// x、y坐标

    private JpanelXingCardMain JpanelXingCardMain;

    /** 实例化界面 */
    public static JframeXingCardMain getJframeSummonEquipMain() {
        return (JframeXingCardMain) FormsManagement.getInternalForm(122).getFrame();
    }

    /** 判断面板是否显示 */
    public static JframeXingCardMain getShowJframeSummonEquipMain() {
        InternalForm form = FormsManagement.getInternalForm2(122);
        if (form == null) {
            return null;
        }
        JframeXingCardMain equipMain = (JframeXingCardMain) form.getFrame();
        return equipMain.isVisible() ? equipMain : null;
    }

    public JframeXingCardMain() {
        super();
        JpanelXingCardMain = new JpanelXingCardMain();
        this.add(JpanelXingCardMain);
        this.setBorder(BorderFactory.createEmptyBorder());// 去除内部窗体的边框
        ((BasicInternalFrameUI) this.getUI()).setNorthPane(null);// 去除顶部的边框
        this.setBounds(200, 120, 700, 537);
        this.setOpaque(false);
        this.pack();
        this.setBackground(UIUtils.Color_BACK);
        this.setVisible(false);

        this.addMouseMotionListener(new MouseMotionListener() {// 判断窗口移动的位置

            @Override
            public void mouseMoved(MouseEvent e) {
                if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE13)) {
                    MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
                }
            }

            @Override
            public void mouseDragged(MouseEvent e) {
                if (getJframeSummonEquipMain().isVisible()) {
                    int x = e.getX() - first_x;
                    int y = e.getY() - first_y;
                    getJframeSummonEquipMain().setBounds(x + getJframeSummonEquipMain().getX(),
                            y + getJframeSummonEquipMain().getY(), getJframeSummonEquipMain().getWidth(),
                            getJframeSummonEquipMain().getHeight());
                }
            }
        });
        this.addMouseListener(this);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
    }

    @Override
    public void mousePressed(MouseEvent e) {
        // 开启窗口音效
        Music.addyinxiao("关闭窗口.mp3");
        if (e.isMetaDown()) {// 检测鼠标右键单击
            // 关闭窗口音效
            // Music.addyinxiao("关闭窗口.mp3");
            FormsManagement.HideForm(122);

        } else {
            FormsManagement.Switchinglevel(122);
        }
        this.first_x = e.getX();
        this.first_y = e.getY();

    }

    @Override
    public void mouseReleased(MouseEvent e) {
    }

    @Override
    public void mouseEntered(MouseEvent e) {
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }


    public int getFirst_x() {
        return first_x;
    }

    public void setFirst_x(int first_x) {
        this.first_x = first_x;
    }

    public int getFirst_y() {
        return first_y;
    }

    public void setFirst_y(int first_y) {
        this.first_y = first_y;
    }

    public JpanelXingCardMain getJpanelXingCardMain() {
        return JpanelXingCardMain;
    }

    public void setJpanelXingCardMain(JpanelXingCardMain JpanelXingCardMain) {
        this.JpanelXingCardMain = JpanelXingCardMain;
    }

}
